import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-workflow/wf/processDesign/list',
  get = '/api-workflow/wf/processDesign/detail',
  save = '/api-workflow/wf/processDesign/save',
  edit = '/api-workflow/wf/processDesign/update',
  delete = '/api-workflow/wf/processDesign/delete',
  deleteBatch = '/api-workflow/wf/processDesign/deleteBatch',
  updateDefine = '/api-workflow/wf/processDesign/updateDefine',
  deploy = '/api-workflow/wf/processDesign/deploy',
  redeploy = '/api-workflow/wf/processDesign/redeploy',
  listByType = '/api-workflow/wf/processDesign/listByType',
  exportXls = '/api-workflow/wf/processDesign/export',
  importExcel = '/api-workflow/wf/processDesign/import',
}

/**
 * 导出api
 */
export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;

/**
 * 分页查询流程设计列表
 * @param params 查询参数
 * @returns
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 获取流程设计详情
 * @param params 查询参数
 * @returns
 */
export const getProcessDesignById = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 保存或更新流程设计
 * @param params
 */
export const saveOrUpdateProcessDesign = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 单条删除流程设计
 * @param params
 */
export const deleteProcessDesign = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除流程设计
 * @param params
 */
export const batchDeleteProcessDesign = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 更新流程设计定义
 * @param params
 * @returns
 */
export function updateProcessDefine(params) {
  return defHttp.post({ url: Api.updateDefine, params });
}

/**
 * 部署流程定义
 * @param params
 * @returns
 */
export function deployProcessDesign(params) {
  return defHttp.post({ url: Api.deploy, params });
}

/**
 * 重新部署流程定义
 * @param params
 * @returns
 */
export function redeployProcessDesign(params) {
  return defHttp.post({ url: Api.redeploy, params });
}

/**
 * 按流程分类给流程设计分组
 * @param params
 * @returns
 */
export function getProcessDesignListByType(params) {
  return defHttp.get({ url: Api.listByType, params });
}
